/*
 * HubDAO.java
 *
 * Created on June 24, 2007, 7:36 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jhub.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import jhub.Hub;

/**
 *
 * @author dbotelho
 */
public class HubDAO  extends AbstractDAO {
    
     private final PreparedStatement getHubByIDStatement;
     
    
    /** Creates a new instance of HubSessionDAO */
    public HubDAO(Connection conn) throws SQLException {
        super(conn);
        this.getHubByIDStatement = conn.prepareStatement("SELECT * FROM hub WHERE hub.id =?");
    }
    
   
    public Hub getHubByID(int id) throws SQLException{
        Hub hub = new Hub();
        getHubByIDStatement.setInt(1,id);
        ResultSet rs = getHubByIDStatement.executeQuery();
        if(rs.next()){
            hub.setId(rs.getInt("id"));
            hub.setPort(rs.getInt("hub_port"));
            hub.setHubName(rs.getString("hub_name"));
            hub.setHubTopic(rs.getString("hub_topic"));
            hub.setMTOD(rs.getString("hub_mtod"));
            hub.setDefaultKickTime(rs.getInt("default_kick_time"));
        }
        return hub;
    }
    
}
